package com.jinlejia.bbs.logic.mine;

import android.content.Context;

import com.alibaba.fastjson.JSONObject;
import com.jinlejia.bbs.http.utils.BBSConfig;
import com.jinlejia.bbs.http.utils.HttpCallBack;

import static com.jinlejia.bbs.http.utils.HttpUtils.JsonParse;
import static com.jinlejia.bbs.http.utils.HttpUtils.httpCallBack;
import static com.jinlejia.bbs.http.utils.HttpUtils.httpCallForm;
/**
 * @author 王进 on 2019/3/28.
 */

public class SaveUserTagLogic {
    private Context context;
    public SaveUserTagLogic(Context context){
        this.context = context;
    }

    public void execute(String tags, final LogicCallBack callBack){
        JSONObject json = new JSONObject();
        json.put("tags",tags);
        String url = BBSConfig.updateUserTags;
        httpCallForm(url,json)
                .execute(httpCallBack(context, new HttpCallBack() {
                    @Override
                    public void onError(Exception e) {
                        callBack.onResult(false);
                    }

                    @Override
                    public void onResponse(JsonParse parse) {
                        boolean result = parse.parse(Boolean.class);
                        callBack.onResult(result);
                    }

                    @Override
                    public void onNoResponse(int code) {
                        callBack.onResult(false);
                    }
                }));
    }

    public interface LogicCallBack{
        void onResult(boolean flag);
    }
}
